package com.wlt.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wlt.domain.User;

@Controller
@RequestMapping("/user") // 窄化处理
public class UserDemoController {
	private List<User> list = new ArrayList<User>();

	/*public UserDemoController() {
		list.add(new User(1, "张三", "1111"));
		list.add(new User(2, "李四", "1111"));
		list.add(new User(3, "王五", "1111"));
	}

	// 查询所有用户
	@RequestMapping("/list")
	public String list(ModelMap map) {
		map.addAttribute("list", list);
		return "/list";
	}

	// 添加用户
	@RequestMapping("/add")
	public String add(User user) {
		user.setId(list.get(list.size() - 1).getId() + 1);
		list.add(user);
		return "redirect:list.do";
	}

	// 删除用户
	@RequestMapping("/delete")
	public String delete(int id) {
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId() == id) {
				list.remove(i);
				break;
			}
		}
		return "redirect:list.do";
	}

	@RequestMapping(value="/{id}/delete1")
	public String delete1(@PathVariable int id) {
		System.out.println(id);
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getId() == id) {
				list.remove(i);
				break;
			}
		}
		return "redirect:/user/list.do";
	}
*/
}
